#pragma once
#include"../../src_baseClasses/DataParser.h"
#include "Data_lines.h"
#include <vector>
#include <QString>

#include <QFile>
#include <QTextStream>

enum TYPE {
	PRE_LINE,
	POST_LINE
};

class DataParser_post : public DataParser {
private:
	double defaltWidth_ = 1;		    //默认线宽
	//数据标记
	std::vector<QString> wiresSymbol;	//走线
	std::vector<QString> fixLiSymbol;	//边界
	std::vector<QString> obss_Symbol;	//多边形障碍物
	std::vector<QString> lockLSymbol;    //锁定线段
	std::vector<QString> miterSymbol;	//miter
	std::vector<QString> diDirSymbol;	//是否差分线
	std::vector<QString> diGapSymbol;	//差分线每段线段的gap
	std::vector<QString> spcssSymbol;    //差分线每段线段的space

	void setSymbols() {
		wiresSymbol = { "#vec_PolyLine" ,"#lines"};		//走线
		fixLiSymbol = { "#fix" };													            //边界线段
		obss_Symbol = { "#obs" ,"#Obs" };								                        //多边形障碍物
		lockLSymbol = { "#lockLines","#lockLine","#lock_lines","#lock_line" };                  //锁定线段
		miterSymbol = { "#LeastSegmentLength" ,"#miter" ,"#Miter" };			                //miter
		diDirSymbol = { "#diffInfo_dir" ,"#DiffInfo_dir","#diffdir","#Diffdir" };		        //是否差分线
		diGapSymbol = { "#diffgap", "#diff_gap", "#diffGap" };			                        //差分线每段线段的gap
		spcssSymbol = { "#spaces", "#Spaces" };                                                 //差分线每段线段的space
	}
	bool isSymbol(QString& line, std::vector<QString>& symbolArray) {
		bool result = false;
		for (auto&& symbol : symbolArray) {
			result = line.startsWith(symbol);
			if (result)
				return true;
		}
		return false;
	}
public:
	DataParser_post(Data_lines* data) : m_data(data) {
		setSymbols();
	};
	~DataParser_post() {};

	//实例化基类虚函数
	bool readFile(const QString& qFullName);
	bool saveFile(const QString& qFullName);
	bool saveFileAs(const QString& qFullName);
	void setMinMax();

public:
	//3.文件输出
	
private:
	Data_lines* m_data;
	struct numbers { //用于读取数据
		double num1;
		double num2;
		double num3;
		double num4;
		double num5;

		double& operator[](int index) {
			switch (index) {
			case 0: return num1;
			case 1: return num2;
			case 2: return num3;
			case 3: return num4;
			case 4: return num5;
			default: throw std::out_of_range("Index out of range");
			}
		}
	};
	numbers m_nums;
	bool read_post(const QString& qFullName);
	int parseLine(QString& line, numbers& nums);
	void fillBlankData(std::vector<std::vector<numbers>>& wireCoordinates,
		std::vector<std::vector<std::vector<numbers>>>& obsCoordinates,
		std::vector<std::vector<numbers>>& fixlinesCoordinates,
		std::vector<std::vector<numbers>>& locklinesCoordinates,
		std::vector<std::vector<double>>& gapCoordinates,
		std::vector<std::vector<double>>& spacesCoordinate,
		std::vector<int>& diffInfo_dirsCoordinates, int add);   //补全缺失的数据,以便能数据一一对应
};